<?php
/**
 * BaseModel.class.php
 * 基类模型
 * 
 * @author 	王中艺	<wangzy_smile@qq.com>
 * @date 	2017-05-04
 */

namespace Wechat\Model;
use Think\Model;

class BaseModel extends Model {

	public 	$errMsg 	= false;

	/**
	 * 字段解析
	 * @param 	$type
	 * @param 	$info
	 * @param 	$isList
	 * @return 	$info
	 */
	protected function _analyField($type, $info, $isList = false){
		switch($type){
			//电台字段解析
			case 'radio':
				if($isList){
					foreach($info as &$item){
						$item['create_date']	= date('Y-m-d', $item['create_time']);
						$item['update_date']	= date('Y-m-d', $item['update_time']);
						$item['banner']		= C('SERVER_CDN').$item['banner'];
						$item['audio']		= C('SERVER_CDN').$item['audio'];
						$item['audio_ii']		= C('SERVER_CDN').$item['audio_ii'];
					}
				}else{
					$info['create_date']	= date('Y-m-d', $info['create_time']);
					$info['update_date']	= date('Y-m-d', $info['update_time']);
					$info['banner']	= C('SERVER_CDN').$info['banner'];
					$info['audio']		= C('SERVER_CDN').$info['audio'];
					$info['audio_ii']		= C('SERVER_CDN').$info['audio_ii'];
				}
			break;

			//留言字段解析
			case 'leaveMsg':
				if($isList){
					foreach($info as &$item){
						$item['relate_type_text']	= C('LMSG_TYPE.'.$item['relate_type']);
						$item['create_date']	= date('Y-m-d', $item['create_time']);
						$item['res_create_date']= date('Y-m-d', $item['res_create_time']);
					}
				}
			break;

			//活动字段解析
			case 'activity':
				$status 	= [1 => '正常', -1 => '删除'];
				if($isList){
					foreach($info as &$item){
						$item['create_date']	= date('Y-m-d', $item['create_time']);
						$item['update_date']	= date('Y-m-d', $item['update_time']);
						$item['banner']		= C('SERVER_CDN').$item['banner'];
						$item['audio']		= C('SERVER_CDN').$item['audio'];
						$item['i_audio']	= C('SERVER_CDN').$item['i_audio'];
						$item['status_text']	= $status[$item['status']];
					}
				}else{
					$info['create_date']	= date('Y-m-d', $info['create_time']);
					$info['update_date']	= date('Y-m-d', $info['update_time']);
					$info['banner']	= C('SERVER_CDN').$info['banner'];
					$info['audio']		= C('SERVER_CDN').$info['audio'];
					$info['i_audio']	= C('SERVER_CDN').$info['i_audio'];
					$info['status_text']	= $status[$info['status']];
				}
			break;

			//活动须知字段解析
			case 'activityknown':
				$status 	= [1 => '正常', -1 => '删除'];
				if($isList){
					foreach($info as &$item){
						$item['create_date']	= date('Y-m-d', $item['create_time']);
						$item['update_date']	= date('Y-m-d', $item['update_time']);
						$item['audio']		= C('SERVER_CDN').$item['audio'];
						$item['audio_time']	= sprintf('%02d′ %02d″', floor($item['audio_time']/60), $item['audio_time']%60);
						$item['status_text']	= $status[$item['status']];
					}
				}else{
					$info['create_date']	= date('Y-m-d', $info['create_time']);
					$info['update_date']	= date('Y-m-d', $info['update_time']);
					$info['audio']		= C('SERVER_CDN').$info['audio'];
					$info['audio_time']	= sprintf('%02d′ %02d″', floor($info['audio_time']/60), $info['audio_time']%60);
					$info['status_text']	= $status[$info['status']];
				}
			break;

			//幸福语录字段解析
			case 'motto':
				$status 	= [1 => '正常', -1 => '删除'];
				if($isList){
					foreach($info as &$item){
						$item['sim_title']	= cut_str($item['title'], 5);
						$item['create_date']	= date('Y-m-d', $item['create_time']);
						$item['update_date']	= date('Y-m-d', $item['update_time']);
						$item['picture']		= C('SERVER_CDN').$item['picture'];
						$item['audio']		= C('SERVER_CDN').$item['audio'];
						$item['status_text']	= $status[$item['status']];
					}
				}else{
					$info['sim_title']	= cut_str($info['title'], 5);
					$info['create_date']	= date('Y-m-d', $info['create_time']);
					$info['update_date']	= date('Y-m-d', $info['update_time']);
					$info['picture']		= C('SERVER_CDN').$info['picture'];
					$info['audio']		= C('SERVER_CDN').$info['audio'];
					$info['status_text']	= $status[$info['status']];
				}
			break;

			case 'activity_picture':
				if($isList){
					foreach($info as &$item){
						$item['path']	= C('SERVER_CDN').$item['path'];
						$item['beautify_path']	= C('SERVER_CDN').$item['beautify_path'];
					}
				}

			default: break;
		}

		return $info;
	}
	
}